package com.gensdai.leliang.db;

import android.content.Context;
import android.util.Log;

import com.gensdai.leliang.AppApplication;
import com.tencent.wcdb.database.SQLiteDatabase;
import com.tencent.wcdb.database.SQLiteOpenHelper;

/**
 * Created by zsxx on 2017/8/1.
 */

public class SqlDBHelp extends SQLiteOpenHelper {

    private static final int DB_VERSION = 4;

    public SqlDBHelp(Context context) {
        super(context, AppApplication.DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        String sql = "create table if not exists " + SearchDao.TABLE_NAME + " (Id INTEGER PRIMARY KEY AUTOINCREMENT, SearchStr TEXT NOT NULL ,CountIn INTEGER DEFAULT 0, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)";
        sqLiteDatabase.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        String sql = "DROP TABLE IF EXISTS " + SearchDao.TABLE_NAME;
        Log.d("SqlDBHelp","onUpgrade");
        sqLiteDatabase.execSQL(sql);
        onCreate(sqLiteDatabase);
    }
}
